<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2020 All rights reserved.
// +----------------------------------------------------------------------
// | User: Simony <1362229026@qq.com>
// | wechat: Shen86579595
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\controller\Common;
use think\Db;

class Report extends Common
{


    /**
     * User:Simony
     * Function: 举报类型列表
     * @return mixed
     */
    public function type()
    {

        //params
        $content_id = input('get.content_id/d', '');

        //where
        $where = [];
        $content_id && $where['content_id'] = $content_id;

        //model
        $reportTypeModel = model('common/report/ReportType');

        //getData
        $data = $reportTypeModel->getList($where, 10);


        //assign
        $this->assign('data', $data);
        $this->assign('page', $reportTypeModel->page_info->render());
        return $this->fetch();
    }

    /**
     * User:Simony
     * Function: 举报类型
     * @return mixed
     */
    public function typeAdd()
    {

        //params
        $id = input('param.id/d', '');

        //model
        $reportTypeModel = model('common/report/ReportType');

        if ($this->request->isAjax()) {

            //params
            $data = [
                'name' => input('post.name'),
                'sort' => input('post.sort'),
            ];

            $res = $id ? $reportTypeModel->edit(['id' => $id], $data) : $reportTypeModel->add($data);
            $res ? ds_json_encode('ret', '操作成功') : ds_json_encode('err', '操作失败');
        }

        //getData
        $data = $reportTypeModel->getInfoByID($id);
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * User:Simony
     * Function: 举报用户
     * @return mixed
     */
    public function user()
    {
        //params
        $type_id = input('get.type_id/d',-1);
        $content = input('get.content/s', '');
        $field = input('get.field', '');
        $value = input('get.value', '');

        //where
        $where = [];
        if ($field) $where[] = [$field, 'eq', $value];

        //judge
        if($type_id>0) $where['type_id'] = $type_id;
        if($content) $where['c.content'] =   ['like','%'.$content.'%'];

        //model
        $reportUserModel = model('common/report/ReportUser');
        $reportTypeModel = model('common/report/ReportType');

        //getData
        $field='ru.*,m.nickname as m_nickname,rm.nickname as rm_nickname,c.content,rt.name as rt_name';
        $data = $reportUserModel->getReportUserList($where, 10,$field);
//        echo $reportUserModel->getLastSql();die;

        $type_list=$reportTypeModel->getList();

        //assign
        $this->assign('data', $data);
        $this->assign('type_list',$type_list);
        $this->assign('page', $reportUserModel->page_info->render());
        return $this->fetch();
    }


}
